package center_event

import (
	"errors"
	"fmt"
)

type (
	onConnectEvent struct {
	}
	onConnectCallback = func()
)

var OnConnect = new(onConnectEvent)

func (event *onConnectEvent) Verify(callback interface{}) (err error) {
	if _, ok := callback.(onConnectCallback); !ok {
		err = errors.New("not on connect event callback function")
	}

	return
}

func (event *onConnectEvent) Call(callback interface{}, args []interface{}) (err error) {
	const ArgsCount = 0
	if len(args) < ArgsCount {
		err = fmt.Errorf("on connect event callback need %d arg", ArgsCount)
		return
	}

	call := callback.(onConnectCallback)
	call()

	return
}

type (
	onDisconnectEvent struct {
	}
	onDisconnectCallback = func()
)

var OnDisconnect = new(onDisconnectEvent)

func (event *onDisconnectEvent) Verify(callback interface{}) (err error) {
	if _, ok := callback.(onDisconnectCallback); !ok {
		err = errors.New("not on disconnect event callback function")
	}

	return
}

func (event *onDisconnectEvent) Call(callback interface{}, args []interface{}) (err error) {
	const ArgsCount = 0
	if len(args) < ArgsCount {
		err = fmt.Errorf("on disconnect event callback need %d arg", ArgsCount)
		return
	}

	call := callback.(onDisconnectCallback)
	call()

	return
}
